package com.guodi.map.controller;

import com.guodi.core.boot.ctrl.BaseController;
import com.guodi.core.tool.api.R;
import com.guodi.map.utils.SDEdbUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.sql.SQLException;
import java.util.List;

/**
 * @描述：sde数据库操作类
 * @作者: 陈宏成
 * @日期: 2021-09-24
 */
@Validated
@RestController
@RequestMapping("/MapSdeDb")
@Api(value = "API - MapSdeDbController", tags = "sde数据库操作类")
public class MapSdeDbController extends BaseController {

    @Resource
    private SDEdbUtils sdEdbUtils;

    /**
     * @描述：获取sde指定表指定字段的取值列表
     * @作者: 陈宏成
     * @日期: 2021-09-24
     */
    @PostMapping("/listFieldValue")
    @ApiOperation(value = " 获取sde指定表指定字段的取值列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "table", value = "表名", required = true,dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "field", value = "字段名", required = true,dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "returnNumMax", value = "返回数量上限，默认200", dataType = "int", paramType = "query"),
    })
    public R listFieldValue(@NotEmpty(message = "table参数不能为空") String table, @NotBlank(message = "field参数不能为空") String field, Integer returnNumMax) throws SQLException, ClassNotFoundException {
        List<Object> fieldValueList = sdEdbUtils.listFieldValue(table, field,returnNumMax == null? 200: returnNumMax);
        return R.data(fieldValueList);
    }


}
